package view;

import com.trolltech.qt.QSignalEmitter;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QPlastiqueStyle;

import trafficAgent.TrafficAgent;

public class ViewThread extends Thread {
	
	private final TrafficAgent agent;
	private MainWindow m;
	private Emitter e;
	

	
	public ViewThread(final TrafficAgent t) {
		agent = t;
		

	}
	
	public void doRepaint(){
		if(m!=null)
			e.updateNeeded.emit();
	}
	
	@Override
	public void run() {	
		final String[] arg = new String[10];
		QApplication.initialize(arg);
		QApplication.setStyle(new QPlastiqueStyle());
		ImageLoader.get().init();      
		m = new MainWindow(agent);
		e = new Emitter();
		m.show();	
		QApplication.exec();
		
	}
	
	private class Emitter extends QSignalEmitter{
		private final Signal0 updateNeeded;
		
		public Emitter() {
			updateNeeded = new Signal0();
			updateNeeded.connect(m,"repaint()");
		}
		
	}

}
